﻿using System;
using System.Collections;
using RAP.Framework.Libary.Utils;

namespace RAP.Framework.Libary.DomTemplateBuilder.Handler.TimeIterate
{
  /// <summary>
  /// 月时间迭代器的Handler
  /// </summary>
  public class MonthIterateHandler : TimeIterateBaseHandler
  {
    protected override IList CreateTimeList(DateTime startDate, DateTime endDate)
    {
      var listTimes = new ArrayList();
      var endMonthId = endDate.MonthId();
      var monthNow = DateTime.Now.MonthId();
      for (var date = startDate; date.MonthId() <= endMonthId; date = date.AddMonths(1))
      {
        listTimes.Add(new Hashtable()
        {
          {
            TIME_ID_FIELD, date.MonthId ( )
          },
          {
            QUARTER_ID_FIELD, date.QuarterId ( )
          },
          {
            QUARTER_FIELD, date.Quarter()
          },
          {
            YEAR_ID_FIELD, date.Year
          },
          {
            START_DATE_FIELD, date.MonthFirstDay ( ).NotLessThan ( startDate ).ToString( "yyyy-MM-dd" )
          },
          {
            END_DATE_FIELD, date.MonthLastDay ( ).NotGreaterThan ( endDate ).ToString( "yyyy-MM-dd" )
          },
          {
            IS_CURRENT_TIME_FIELD, date.MonthId() == monthNow
          }
        });
      }
      return listTimes;
    }
  }
}
